<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>财务管理 - 销售奖励</title>
<?php include($this->c['_homes']['_viewsHome'].'/_global/_head.php');?>
</head>
<!-- BEGIN BODY -->
<body class="page-header-fixed page-sidebar-fixed">
<!-- BEGIN HEADER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/head.php');?>
<!-- END HEADER -->
<div class="clearfix"></div>
<!-- BEGIN CONTAINER -->
<div class="page-container" > 
  <!-- BEGIN HORIZONTAL MENU PAGE SIDEBAR1 -->
  <?php include($this->c['_homes']['_viewsHome'].'/_global/menu.php');?>
  <!-- END BEGIN HORIZONTAL MENU PAGE SIDEBAR --> 
  <!-- BEGIN PAGE -->
  <div class="page-content"> 
    <!-- BEGIN PAGE HEADER-->
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title"> 销售奖励</h3>
        <ul class="page-breadcrumb breadcrumb">                       
          <li> <i class="icon-home"></i> <a href="/manage">后台</a> <i class="icon-angle-right"></i> </li>
          <li> 财务管理 <i class="icon-angle-right"></i> </li>
          <li>销售奖励</li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB--> 
      </div>
    </div>
    <!-- END PAGE HEADER--> 
    <!-- BEGIN PAGE CONTENT-->
    <div class="row">
      <div class="col-md-12">
        <div class="portlet box">
          <div class="booking-search">
            <form action="" role="form" method="get" onSubmit="return chkfrm();">
              <div class="row form-group">
                  <div class="col-md-2">
                      <select class="form-control" name="caid" id="caid">
                          <option value="">未选择分类</option>
                          <?php
                          if($this->cate){
                              foreach($this->cate as $k=> $r){
                                  if(isset($_GET['caid']) && $r['caid']==$_GET['caid']) $slk = ' selected';
                                  else $slk = '';
                                  ?>
                                  <option value="<?=$r['caid'];?>"<?=$slk;?>><?=$r['name'];?></option>
                                  <?
                              }
                          }
                          ?>
                      </select>
                  </div>       
                  <div class="col-md-2">                                
                      <div class="input-group input-medium">
                          <input class="form-control" type="text" placeholder="开始时间" readonly="readonly" id="_start_time" name="start_time" value="<?=$this->start_time;?>">
                          <span class="input-group-btn">
                          <button class="btn default" type="button"><i class="icon-calendar"></i></button>
                          </span>
                        </div>
                    </div>
                   <div class="col-md-2">                                
                    <div class="input-group input-medium ">
                      <input class="form-control" type="text" placeholder="结束时间" readonly="readonly" id="_end_time" name="end_time" value="<?=$this->end_time;?>">
                      <span class="input-group-btn">
                      <button class="btn default" type="button"><i class="icon-calendar"></i></button>
                      </span>
                      </div>
                  </div>
                  <div class="col-md-2">
                      <select class="form-control" name="teampercent">
                          <option value="">团队业绩占比0</option>
                          <?php
                          for($i=1;$i<=50;$i++)
                          {
                            $p = $i/100;

                            if($_GET['teampercent'] == $p)
                            {
                              $slk = ' selected';
                            }
                            else
                            {
                              $slk = '';
                            }

                            echo '<option value="'.$p.'"'.$slk.'>团队业绩占比'.$i.'%</option>';
                          }
                          ?>
                      </select>
                  </div>
                  <div class="col-md-1"><input type="submit" class="btn blue btn-block" value="统 计"></div>
              </div>
              <?php if($this->pv['as']){?>
              <div class="row form-group">
                <div class="col-md-2">
                      <div class="input-cont">
                          <input class="form-control"  id="award_money" name="award_money" placeholder="发放奖励金额" value="" type="text">
                      </div>
                </div>
                  <div class="form-group">
                      <div class="col-md-6">
                          <div class="radio-list">
                              <label class="radio-inline">
                                  <div id="special_status" class="radio"><span class="">
                              <div class="radio" id="uniform-optionsRadios4"><span><input name="type" id="type" value="1" type="radio" ></span></div>
                              </span></div>
                                  <span class="label label-success">硒豆</span>
                              </label>
                              <label class="radio-inline">
                                  <div id="ios_audit" class="radio"><span>
                              <div class="radio" id="uniform-optionsRadios5"><span class=""><input name="type" id="type" value="2" type="radio"></span></div>
                              </span></div>
                                  <span class="label label-danger">金花</span>
                              </label>
                          </div>
                      </div>
                  </div>
                <div class="col-md-1"><input type="button" class="btn green btn-block" value="发放奖励" onclick="ajaxSub();"></div>
              </div>
              <?php }?>
            </form>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN SAMPLE TABLE PORTLET-->
          <form id="forms">
        <div class="portlet box blue">
          <div class="portlet-title">
            <div class="caption"><i class="icon-list"></i>总人数<?=count($this->data['daili']);?>位&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;符合条件<?=$this->data['xiaonum']? : 0;?>位&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;符合条件占比<?=$this->data['xiaoman'] > 0 ? $this->data['xiaoman'] * 100 : 0;?>%</div>
            <div class="tools"> <a href="javascript:;" class="collapse"></a> </div>
          </div>
          <div class="portlet-body">
            <div class="table-scrollable">
             <table class="table table-striped table-bordered table-hover dataTable">
              <thead>
                <tr>
                  <th><input type="checkbox" id="_checkboxall" value="1"></th>
                  <th>UID</th>
                  <th>昵称</th>
                  <th>姓名</th>
                  <th>推荐码</th>
                  <th>手机号码</th>
                   <th>自购金额</th>
                  <th>直推业绩</th>
                  <th>小市场业绩</th>
                  <th>团队销售额</th>
                  <th>小市场业绩总和</th>
                  <th>业绩分子</th>
                  <th>业绩分母</th>
                  <th>预发金额比例</th>
                  <th>预发金额</th>
                </tr>
              </thead>
             <tbody>
               <?php
            			if($this->data['daili'])
            			{			
            				foreach($this->data['daili'] as $k=> $r){
            			?>
                <tr>
                <?php 
                    if($r['status']==1 && $r['commission_rate']>0){
                        
                        
                
                    ?>
                    <td><input type="checkbox" class="_checkboxs" name="uid[]" value="<?=$r['uid'];?>"></td>
                    <input type="hidden" name="commission_rate[<?=$r['uid'];?>]" value="<?=$r['commission_rate'];?>">
                    <input type="hidden" name="my_order_money[<?=$r['uid'];?>]" value="<?=$r['zigou'];?>">
                    <input type="hidden" name="level_total_money[<?=$r['uid'];?>]" value="<?=$r['zhitui'];?>">
                    <input type="hidden" name="subtract_total_order_money[<?=$r['uid'];?>]" value="<?=$r['xiao'];?>">
                    <input type="hidden" name="team_total_order_money[<?=$r['uid'];?>]" value="<?=$r['zong'];?>">
                  <?php }else{?>
                      
                     <td></td>  
                   <?php  } ?>   
                 
                  <td><?=$r['uid'];?></td>
                  <td><?=$this->data['user'][$r['uid']]['realname']?></td>
                  <td><?=$this->data['user'][$r['uid']]['name']?></td>
                  <td><?=$this->data['user'][$r['uid']]['recode']?></td>
                  <td><?=$this->data['user'][$r['uid']]['mobile'];?></td>
                  <td><?=$r['zigou'];?></td>
                  <td><?=$r['zhitui'];?></td>
                  <td><?=$r['xiao'];?></td>
                  <td><?=$r['zong'];?></td>                  
                  <td><?=$this->data['xiaozong'];?></td>
                  <td><?=$r['fenzi']? $r['fenzi'] : 0;?></td>
                  <td><?=$this->data['fenmu'];?></td>
                  <td><?=$r['commission_rate'] *100;?>%</td>
                  <td class="commission_money" rate="<?=$r['commission_rate']?>"></td>
                </tr>
                <?
        					}
        				}
        				?>
				 </tbody>                                
            </table>
            </div>
          </div>
        </div>

          </form>        
        <!-- END SAMPLE TABLE PORTLET--> 
      </div>
    </div>
    <!-- END PAGE CONTENT--> 
  </div>
  <!-- END PAGE --> 
</div>
<!-- END CONTAINER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/_footer.php');?>
<script type="text/javascript" src="/style/js/layer/laydate.js"></script>
<script type="text/javascript" src="/style/js/layer/layer.min.js"></script>
<script>
jQuery(document).ready(function() {
   App.init();
    jQuery('#_checkboxall').change(function () {
        var checked = jQuery(this).is(":checked");
        jQuery("._checkboxs").each(function () {
            if (checked) {
                $(this).attr("checked", true);
            } else {
                $(this).attr("checked", false);
            }
            $(this).parents('tr').toggleClass("active");
        });
        jQuery.uniform.update("._checkboxs");
    });

    $("._checkboxs").change(function() {
        var checked = jQuery(this).is(":checked");
        if (!checked) {
            $(this).attr("checked", false);
            $(this).parents('tr').removeClass("active");
            $("#_checkboxall").attr("checked",false);
            jQuery.uniform.update("#_checkboxall");
        }
    });
   


laydate.render({
  elem: '#_start_time', //指定元素
  type: 'datetime',
  format:"yyyy-MM-dd HH:mm:ss"
});

laydate.render({
  elem: '#_end_time', //指定元素
  type: 'datetime',
  format:"yyyy-MM-dd HH:mm:ss"
});

});



function chkfrm()
{
    if($("#caid").val()==""){
        swal("请选择分类");
        return false;

    }

    if($("#month").val()==""){
        swal("请选择月份");
        return false;

    }

}

$("#award_money").on('input propertychange', function(){
    if($(this).val()){
        var m  = parseInt($(this).val());
        $(".commission_money").each(function(i,v){
              var rate = $(this).attr("rate");
            $(this).html((rate *m).toFixed(2) );
        });
   }else{
        $(".commission_money").html("");
    }
})


function ajaxSub()
{
    cm = confirm("您确定发放吗");
    if(cm){

        var _ids = '';
        $("._checkboxs").each(function () {
            if( $(this).attr("checked")  ) {
                if(_ids!="") _ids +=',';
                _ids += $(this).val();
            }
        });

        if($("#award_money").val() =="" || parseFloat($("#award_money").val()) <=0){

            swal("请输入发放金额");
            return false;

        }
        var type=$('input:radio[name="type"]:checked').val();
         if(!type){
             swal("请选择硒豆或者金花");
             return false;
         }


      
        if(_ids !=''){
            
            $.ajax({
                url:'/finance/ajax',
                type:'post',
                data: $("#forms").serialize() + "&user_ids="+_ids+"&mr=" + Math.random()+"&act=award_send&start_time=<?=$this->start_time;?>&caid=<?=$_GET['caid']?>&award_money="+$("#award_money").val()+"&type="+type,
                dataType:'json',
                success:function(json){
                   	 if(json.code==200)
      	  	        {
      	  	          swal(json.msg,false,"success");
      		  	        window.location.reload();    
    
      	  	        }
      	  	        else{
      	  	          swal(json.msg,"错误代码["+json.code+"]","error");
      	  	        }

                },
                error:function(res){
                    console.log(res)
                }
            })

        }else{

            swal("至少选择一个用户");
        }
    }

}
</script> 
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>